const { Router } = require("express");
const { body, validationResult } = require("express-validator");


// 路由中间件通过后的操作api
const doctorCtrl = require("../controllers/doctorCtrl")
const auth = require("../middleware/auth");

const router = new Router();


/**
 * 查询全部 /api/doctor/getdoctorlist
 * get
 * limit 返回数(默认10)
 * offset 偏移量(默认0)表示跳过指定数量的数据
 */
router.get('/getdoctorlist', auth, doctorCtrl.getdoctorlist)


/**
 * 条件联合筛选 /api/doctor/screen
 * get
 * Department 科室 xx-xxxx格式
 * Doctorname 医生姓名
 */
router.post('/screen', auth, doctorCtrl.getscreen)



/**
 * 根据id数组进行删除 /api/doctor/del
 * post
 * id 表示删除的消息id
 */
router.post('/del', auth, doctorCtrl.delarr)




/**
 * 根据id编辑详情  /api/doctor/edit
 * get
 * id 表示编辑的id
 */
router.get('/edit', auth, doctorCtrl.edit)




let multer = require('multer');
let path = require('path');
const { request } = require("http");

let storage = multer.diskStorage({
    // // 设置图片存储路径
    destination: path.join(__dirname, '../static'),

    // // 设置图片存储时的名字
    filename: function (req, file, cb) {
        console.log('123456');

        console.log('file', file);

        // console.log('req', req);


        let ext = path.extname(file.originalname)

        let filename = file.fieldname + '-' + new Date().getTime() + ext
        cb(null, filename)
    }

})
let upload = multer({ storage: storage })


/**
 * 新增 /api/doctor/add
 * post
 * fromdata 表示携带file对象的数据
 */
router.post('/add', auth, upload.single('img'), doctorCtrl.add)





/**
 * 修改 /api/doctor/change
 * post 
 * 
 */
router.post('/change', auth, upload.single('img'), doctorCtrl.change)




module.exports = router





